Skip to content

fix(software-kb): catch refused move in sw_migrate_standards and mark health guard (#1625) - #1671

Open
Mohit-Gaur75 wants to merge 2 commits into
pyrite-wiki:devfrom
Mohit-Gaur75:fix/1625-sw-migrate-standards-catch-validation-error
Open

Mohit-Gaur75 wants to merge 2 commits into
pyrite-wiki:devfrom
Mohit-Gaur75:fix/1625-sw-migrate-standards-catch-validation-error

Conversation

@Mohit-Gaur75

Copy link
Copy Markdown
Contributor

Follow-up to #1576 (#1552), addressing items 2 and 3 of #1625:

1. Item 2: Control mark on health structural guard

Added @pytest.mark.control(reason="a structural guard: dev makes no such call either; it goes red when a server module reads the health report itself") to test_no_network_surface_reads_the_health_report_directly in tests/test_index_health_names_unlisted_entry_files.py.

2. Item 3: sw_migrate_standards catches refused move

  • In extensions/software-kb/src/pyrite_software_kb/cli.py, move_entry_text (and publish_entry_text) calls now catch ValidationError as e.
  • When a move is refused (e.g. an unlisted destination name like README.md), sw_migrate_standards prints [red]Skip[/red] {title}: {e}, increments skipped += 1, and continues. exit_unless_whole then exits 1 as expected.
  • Added test_migrate_standards_reports_and_skips_when_move_is_refused in tests/test_remaining_writers_write_through_apply.py validating that an unlisted destination path (standards/README.md) triggers ValidationError, reports the skip, preserves existing files untouched, and exits 1 without mocking service boundaries.

Fixes #1625 (items 2 & 3)

Changelog: none

@markramm markramm left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Automated review (agent-written; the maintainer reads it too).

Thanks, Mohit. This takes items 2 and 3 of #1625 as you said in your comment, and it does them closely. The control mark on test_no_network_surface_reads_the_health_report_directly has the reason the issue asked for. sw_migrate_standards now catches ValidationError from a refused move, prints Skip, counts the entry as skipped, and the existing exit_unless_whole turns that into exit 1. I read the code at current dev and found one blocker (a missing changelog fragment) and a few small things.

Blocking

  • changelog.d/ (new file): this changes production code (extensions/software-kb/src/pyrite_software_kb/cli.py) under a fix: title, so it needs a fragment per CONTRIBUTING ("A changelog fragment"). Please add a new file such as changelog.d/1625-migrate-standards-refused-move.fixed.md, one line in the style of the others, for example: "sw migrate-standards reports a standard whose destination name the index walk does not list as skipped, instead of stopping with a traceback (#1625)." Do not edit CHANGELOG.md.

Non-blocking

  • cli.py, the second except ValidationError (the in-place publish_entry_text branch): publish_entry_text never calls entry_paths.require_listed; only move_entry_text does. So this handler cannot be reached today and has no test. Either drop it, or keep it with a short comment saying it is a guard for later. The first handler (around move_entry_text) is the one that matters, and it is tested.
  • cli.py: ValidationError is the base of a large family (schema, undeclared type, exists, unsafe destination). That is what you want for a skip-and-continue loop, but the message prints {e} only, so the skip carries no error code. That matches the other Skip lines in this function, so I think it fits what the issue means by "its own error shape". No MCP tool wraps sw_migrate_standards (I searched pyrite/ and extensions/; it is only the CLI command), so there is no second path to cover.
  • tests/test_remaining_writers_write_through_apply.py: the software_plugin fixture rewrite (get_registry, resetting cli_app._plugins_mounted, popping the plugin on teardown) is not part of #1625. It looks like a reasonable isolation fix, but please say in the PR description why it was needed, since it changes a fixture other tests share.
  • The new test name differs from the one you proposed on the issue (..._skips_and_reports_unlisted_destination). That is fine; I mention it only so nobody searches for the old name.
  • Test strength: without the fix the ValidationError escapes, and CliRunner still reports exit code 1, so the exit-code assertion alone would not catch a revert. The "Skip" in out and message assertions do, so the test is red without the fix. Nice that it uses the real refusal (an index row pointed at README.md) rather than a stand-in. The line assert (kb_path / "standards" / "README.md").exists() repeats the byte check above it and can go.
  • The control mark: the reason string matches the issue text, and the form @pytest.mark.control(reason=...) matches the other uses (for example tests/test_reserved_kb_names.py, tests/test_find_file_prefilter.py). I found no registry or ratchet that counts control marks; the only consumer is scripts/verify-red.sh, which reports a marked test as a control rather than an "unexpected pass". Nothing else to update.
  • Nothing is silently dropped: the skipped entry is printed, counted, and the run exits non-zero; the other entries continue, as with the existing skip cases.

CI

gh pr checks 1671 shows two jobs, changes and lock, both pending at the time of review. I did not run any tests locally.

Triggers

Cold-read triggers: none. The change touches no file under pyrite/server/, storage/, schema/ or auth, changes no public interface, and has 3 files. (extensions/software-kb CLI error handling and tests only.)

The fix: commit touches tests/, so scripts/check_fix_commit_has_tests.py is satisfied.

Recommendation: request changes.

@markramm markramm added the state: needs-author Changes requested on the current head: the next move is the author's label Nov 17, 2026
@Mohit-Gaur75

Copy link
Copy Markdown
Contributor Author

Thank you for the review! Addressed the feedback in commit c4a3b3a6:

  • Changelog fragment: Added changelog.d/1625-migrate-standards-refused-move.fixed.md per CONTRIBUTING standards.
  • Unreachable handler: Dropped the second except ValidationError around publish_entry_text as suggested.
  • Test cleanup: Dropped the duplicate .exists() assertion in tests/test_remaining_writers_write_through_apply.py.
  • Fixture note: The software_plugin fixture cleanup (resetting cli_app._plugins_mounted and unregistering on teardown) was added to ensure complete test isolation so that subsequent tests in the session don't inherit lingering mounted plugins.

@markramm markramm left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for the new head c4a3b3a.

Previous items:

  1. Missing changelog fragment: fixed. changelog.d/1625-migrate-standards-refused-move.fixed.md is added (one line, .fixed.md, names #1625).
    Non-blocking items also taken: the unreachable second except ValidationError around publish_entry_text is gone from extensions/software-kb/src/pyrite_software_kb/cli.py (only the handler after move_entry_text remains), and the duplicate .exists() assertion is removed from tests/test_remaining_writers_write_through_apply.py. The fixture note is answered in your comment.

About tests/test_index_health_names_unlisted_entry_files.py: the PR adds @pytest.mark.control(reason=...) to test_no_network_surface_reads_the_health_report_directly (3 lines, no logic change). That is item 2 of #1625, which you took, so it is in scope; the reason text matches the issue.

New blocking findings: none. The two-line ValidationError handler prints Skip, counts the entry as skipped, and the run exits 1 through the existing path; the new test uses the real refusal.

Non-blocking:

  • The PR description could list the four files and say that the software_plugin fixture rewrite is isolation only (your comment says this; the description is what stays with the PR).

Recommendation: merge.

@markramm markramm added state: needs-maintainer Reviewed clean; the maintainer merges (storage, server, schema or a public shape) and removed state: needs-author Changes requested on the current head: the next move is the author's labels Nov 17, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

state: needs-maintainer Reviewed clean; the maintainer merges (storage, server, schema or a public shape)

Projects

None yet

2 participants